home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / languages / cleo.lzh / Cleo / source / CLEO.C next >
Encoding:
C/C++ Source or Header  |  1993-01-24  |  8.3 KB  |  275 lines

  1. /***************************************************************************
  2. *   Ce fichier, ainsi que tous les  modules  l'accompagnant, peut et  doit *
  3. * etre  copié GRATUITEMENT à la seule condition expresse de conserver      *
  4. * l'INTEGRALITE  du  Code Source, de  la documentation, et  des fichiers   *
  5. * annexes du package. Ce logiciel est Shareware, veuilez envoyer 100 FF à  *
  6. * l'auteur pour recevoir regulièrement les nouvelles versions.             *
  7. * Toute modification est INTERDITE sans l'autorisation écrite de l'auteur. *
  8. *            Tous droits réservés à M. DIALLO Barrou, Juillet 1992.        *
  9. ***************************************************************************/
  10.  
  11. /*#define debug*/
  12. #define verbose
  13. /*                              CLEOBIS Language
  14.                         (C)opyright 1992 by DIALLO Barrou
  15. */
  16.  
  17. #ifdef msdos
  18.         #include "include\\cleobis.h"
  19.         #include "include\\libs.h"
  20.         #include "include\\globals.h"
  21. #else
  22.         #include "include/cleobis.h"
  23.         #include "include/libs.h"
  24.         #include "include/globals.h"
  25. #endif
  26.  
  27. #include <string.h>
  28. #include <ctype.h>
  29.  
  30. void Lexical(void)
  31. {
  32.     BOOL fin=FALSE, bon;
  33.  
  34.          lasttokentype = curtokentype;  /* Sauve l'ancien type */
  35.          lasttokenid = curtokenid;                      /* Sauve l'ancien Id */
  36.  
  37.    do
  38.     {
  39.         bon =TRUE;
  40.         if (isalpha(*curc) || *curc=='_')
  41.             curc=(char *)Lettres(curc);
  42.         else
  43.         if (isnum(*curc))
  44.             curc=(char *)Nombres(curc);
  45.         else
  46.         if (isspace(*curc))
  47.             {
  48.             curc=(char *)Avance(curc);
  49.             bon =FALSE;
  50.             }
  51.         else
  52.             switch(*curc)
  53.             {
  54.             case '\'':
  55.                     curc =(char *)ConstChr(curc);
  56.                     break;
  57.             case '\"':  if (!quote) quote=TRUE;
  58.                             else quote=FALSE;
  59.                     curc++; lg++;
  60.                     break;
  61.             case '\r':
  62.             case '\n':
  63.                     curlg++; curcol=0; lg++;
  64.                     bon =FALSE;
  65. #ifdef verbose
  66.                     printf("# %d\r",curlg-1);
  67. #endif
  68.                     break;
  69.  
  70.             case '-':
  71.                     curtokenid =(int) moins_o;
  72.                     curtokentype = mathope_mt;
  73.                             *curtoken = (*curc);
  74. #ifdef debug
  75.                         printf("OPERATEUR MATH.\t-\n");
  76. #endif
  77.                     curc++; lg++;
  78.                     break;
  79.             case '+':
  80.                     curtokenid =(int) plus_o;
  81.                     curtokentype = mathope_mt;
  82.                             *curtoken = (*curc);
  83. #ifdef debug
  84.                         printf("OPERATEUR MATH.\t+\n");
  85. #endif
  86.                     curc++; lg++;
  87.                     break;
  88.             case '*':
  89.                     curtokenid =(int) fois_o;
  90.                     curtokentype = mathope_mt;
  91.                             *curtoken = (*curc);
  92. #ifdef debug
  93.                         printf("OPERATEUR MATH.\t*\n");
  94. #endif
  95.                     curc++; lg++;
  96.                     break;
  97.             case '/':
  98.                     curtokenid =(int) divise_o;
  99. #ifdef debug
  100.                         printf("OPERATEUR MATH.\t/\n");
  101. #endif
  102.                     curtokentype = mathope_mt;
  103.                             *curtoken = (*curc); *(curtoken+1)=0;
  104.                     curc++; lg++;
  105.                     break;
  106.             case '%':
  107.                     curtokenid =(int) mod_o;
  108. #ifdef debug
  109.                         printf("OPERATEUR MATH.\t/\n");
  110. #endif
  111.                     curtokentype = mathope_mt;
  112.                             *curtoken = (*curc);
  113.                     curc++; lg++;
  114.                     break;
  115.             case '<':
  116.                     if ( *(curc+1) == '>')
  117.                         {
  118.                         curtokenid =(int) different_b;
  119. #ifdef debug
  120.                         printf("BOOLEEN\t<>\n");
  121. #endif
  122.                         curc++; lg++;
  123.                         }
  124.                     else
  125.                     if ( *(curc+1) == '=')
  126.                         {
  127.                         curtokenid =(int) pluspetitegal_b;
  128. #ifdef debug
  129.                         printf("BOOLEEN\t<=\n");
  130. #endif
  131.                         curc++; lg++;
  132.                         }
  133.                     else
  134.                         {
  135.                         curtokenid =(int) pluspetit_b;
  136. #ifdef debug
  137.                        printf("BOOLEEN\t<\n");
  138. #endif
  139.                         }
  140.                     curtokentype = booleen_mt;
  141.                     curc++; lg++;
  142.                     break;
  143.             case '>':
  144.                     if ( *(curc+1) == '=')
  145.                         {
  146.                         curtokenid =(int) plusgrandegal_b;
  147. #ifdef debug
  148.                         printf("BOOLEEN\t>=\n");
  149. #endif
  150.                         curc++; lg++;
  151.                         }
  152.                     else
  153.                         {
  154.                         curtokenid =(int) plusgrand_b;
  155. #ifdef debug
  156.                         printf("BOOLEEN\t>\n");
  157. #endif
  158.                         }
  159.                     curtokentype = booleen_mt;
  160.                     curc++; lg++;
  161.                     break;
  162.  
  163.             case '=':
  164.                     curtokenid =(int) egal_b;
  165.                     curtokentype = booleen_mt;
  166.                     curc++; lg++;
  167. #ifdef debug
  168.                         printf("BOOLEEN\t=\n");
  169. #endif
  170.                     break;
  171.             case '.':
  172.                     if ( *(curc+1) == '.')          /* '..' Mot Reserve! */
  173.                         {
  174.                          strcpy(curtoken, "..");
  175.                          curtokentype = reserved_mt;
  176.                          curtokenid = pp_f;
  177.                          curc++; lg++;
  178. #ifdef debug
  179.                          printf("TOKEN= ..\tMot Reservé!!!\n");
  180. #endif
  181.                         }
  182.                     else
  183.                         {
  184.                           *curtoken='.'; *(curtoken+1)=0;
  185.                           curtokentype = separ_mt;
  186.                     curtokenid = -1;
  187. #ifdef debug
  188.                         printf("SEPARATEUR \t%c\n", *curtoken);
  189. #endif
  190.                         }
  191.                     curc++; lg++;
  192.                     break;
  193.  
  194.             case ',': case '(': case ')': case ';': case '#':
  195.                       case '[': case ']':
  196.                     curtokentype = separ_mt;
  197.                     *curtoken = (*curc); *(curtoken+1)=0;
  198. #ifdef debug
  199.                     printf("SEPARATEUR \t%c\n", *curtoken);
  200. #endif
  201.                     curc++; lg++;
  202.                     curtokenid = -1;
  203.                     break;
  204.             case ':':
  205.                     if (*(curc+1) == '=')
  206.                         {
  207.                          curtokenid =(int) affecte_b;
  208.                          curtokentype = booleen_mt;
  209.                          curc++; lg++;
  210. #ifdef debug
  211.                             printf("BOOLEEN\tAffecte\n");
  212. #endif
  213.                         }
  214.                     else
  215.                         {
  216.                             curtokentype = separ_mt;
  217.                             *curtoken = (*curc);
  218.                     curtokenid = -1;
  219. #ifdef debug
  220.                             printf("SEPARATEUR \t%c\n", *curtoken);
  221. #endif
  222.                         }
  223.                     curc++; lg++;
  224.                     break;
  225.             case '{':
  226.                     while ( *curc != '}')
  227.                      {
  228.                       if (*curc=='\r' || *curc=='\n')
  229.                         {
  230.                           curlg++;
  231. #ifdef verbose
  232.                          printf("# %d\r",curlg-1);
  233. #endif
  234.                         }
  235.                       curc++; lg++;
  236.                      }
  237. #ifdef debug
  238.                             printf("COMMENTAIRE \t%c\n", *curc);
  239. #endif
  240.                     bon =FALSE;
  241.                     curc++; lg++;
  242.                     break;
  243.             case 0:
  244.                     fin=TRUE;
  245.                     break;
  246.             default:
  247.                     printf("*********** ERREUR <%c> INCONNU\n", *curc);
  248.                     curc++; lg++;
  249.                     break;
  250.             }
  251.     } while (!bon);
  252.     if (fin)
  253.         {
  254. #ifdef debug
  255.         ListConst();
  256.         ListVar();
  257.         Dis();
  258. #endif
  259. /* End(); printf("Fin de la compilation\n"); exit(0); */}
  260. }
  261.  
  262. void main(int argc, char **argv)
  263. {
  264.     Intro();
  265.          if (argc>1)
  266.        ReadArg(argc, argv);
  267.     else exit();
  268.     ReadConfig((char *)NULL);
  269.     Begin();
  270. curc =(char *)Txt;
  271.     Compiler();
  272. /*ListVar(); */
  273.     printf("\n%d lignes compilees...\n",curlg);
  274.     End();
  275. }